<template>
  <div class="home-detail">
    <h3>{{pageFormConfig.title}}</h3>
    <pageForm
      :formConfig="pageFormConfig.item"
      ref="pageForm"
    ></pageForm>
    <div
      class="btn"
      v-show="pageFormConfig.item.length>0"
    >
      <!-- 取消重复提交 -->
      <el-button
        type="primary"
        size="mini"
        @click="debounceFunSave"
      >保存</el-button>
    </div>
  </div>
</template>


<script>
// const formConfig = [
//   { label: "实验对象", type: "span", key: "obj", value: "汽车",disabled:true },
//   { label: "名称", type: "text", key: "name", value: "特斯拉" ,disabled:true},
//   { label: "价格", type: "number", key: "price", value: "360000",disabled:false },

//   {
//     label: "类型",
//     type: "select",
//     key: "type",
//     value: "s",
//     disabled:false,
//     list: {
//       data: [
//         { key: "Model 3", value: "3" },
//         { key: "Model X", value: "x" },
//         { key: "Model S", value: "s" },
//       ],
//       labelKey: "key",
//       valueKey: "value",
//     },
//   },
//   {
//     label: "寄送",
//     type: "radio-group",
//     key: "past_untoward_effect",
//     value: "需要",
//     disabled:false,
//     list: {
//       data: [
//         { value: "需要", label: "需要" },
//         { value: "不需要", label: "不需要" },
//         { value: "看看再说", label: "看看再说" },
//       ],
//       labelKey: "label",
//       valueKey: "value",
//     },
//   },
//   {
//     label: "现金支付",
//     key: "cash",
//     value: true,
//     type: "checkbox",
//     disabled:false
//   },
//   { label: "备注", type: "textarea" ,disabled:false, key: "desc", value: "备注" },
// ];
import pageForm from "@/components/pageForm";
export default {
  name: "homeDetail",
  data() {
    return {
      debounceFunSave: null,
    };
  },
  computed: {
    pageFormConfig() {
      return this.$store.state.pageFormConfig;
    },
  },
  components: {
    pageForm,
  },
  created() {
    this.debounceFunSave = this.debounceFun(this.save, 500);
  },
  methods: {
    async save() {
      console.log("我执行了");
      let data = this.$refs.pageForm._getFromConfig();
      let $data = [];
      data.forEach((item) => {
        $data.push({
          disabled: item.disable,
          name: item.key,
          value: item.value,
        });
      });

      let res = await this.$http.post(
        "/dictionary/saveForm?modelName=" +
          this.pageFormConfig.title +
          "&nodeId=" +
          this.pageFormConfig.id,
        $data
      );
      if (res.code == 200) {
        this.$message({
          message: res.msg,
          type: "success",
        });
        // 刷新树
        console.log('刷新')
        this.$bus.$emit("updateTree");
      }
    },
  },
};
</script>

<style lang="scss">
.home-detail {
  margin: 20px 10px;
  h3 {
    font-weight: normal;
    margin-left: 50px;
    margin-bottom: 20px;
  }
  .btn {
    margin-left: 150px;
  }
}
</style>